<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/style.css" />
    <script type="text/javascript" src="__PUBLIC__/Js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/bootstrap.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/ckform.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/common.js"></script>

 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form action="<?php echo U('User/usersave');?>" method="post" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">登录名</td>
        <td><input id="username" type="text" name="username"/></td>
    </tr>
    <tr>
        <td class="tableleft">密码</td>
        <td><input id="password1" type="password" name="password"/></td>
    </tr>
    <tr>
        <td class="tableleft">确认密码</td>
        <td><input id="password2" type="password" name="password"/></td>
    </tr>
    <tr>
        <td class="tableleft">真实姓名</td>
        <td><input id="name" type="text" name="realname"/></td>
    </tr>
    <tr>
        <td class="tableleft">邮箱</td>
        <td><input id="emall" type="text" name="email"/></td>
    </tr>
    <tr>
        <td class="tableleft"></td>
        <td>
            <button type="button" onclick="save()" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
        </td>
    </tr>
</table>
</form>
</body>
</html>
<script>
    function save(){
        var username = $('#username').val();
        var password1 = $('#password1').val();
        var password2 =$('#password2').val();
        var name = $('#name').val();
        var emall =$('#emall').val();

        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if(!username || !password1 || !password2 || !name || !emall){
            alert('请把信息补全!');
            return;
        }
        if(password1.length < 8){
            alert("密码安全级别太低请重新输入。");
            document.getElementById("password1").value="";
            document.getElementById("password2").value="";
            return;
        }
        if (!myreg.test(emall)) {
            alert("请输入正确的邮箱地址。");
            return;
        }
        if(password1 != password2){
            alert('两次输入密码不一致!');
            document.getElementById("password1").value="";
            document.getElementById("password2").value="";
            return;
        }

        $.ajax({
            type : "post",
            dataType : "text",
            url : "<?php echo U('User/usersave');?>",
            data : {
                username : username,
                password : password1,
                name : name,
                emall : emall
            },
            success : function(msg) {
                console.log(msg);
                //alert(msg);
                if (msg == 0) {
                    window.location.href = "<?php echo U('User/index');?>";
                    alert('注册成功'+msg);
                }
                if (msg == 1) {
                    alert('注册失败'+msg);
                }
                if (msg == 2) {
                    alert('登录名不能重复'+msg);
                }
            }
        });
    }

    $(function () {
        $('#backid').click(function(){
            window.location.href="index.html";
        });

    });
</script>